package com.dianganjiao.lib.viewmodel

import android.content.Context
import android.content.Intent
import android.view.View
import com.dianganjiao.lib.base.AbsActivity
import com.dianganjiao.lib.life.ViewModelQuick

abstract class AbsViewPresenter : AbsPresenter() {

    open lateinit var rootView: View

    override fun onCreated(vararg args: Any) {
        rootView = args[0] as View
        onCreatedView(*args)
    }

    abstract fun onCreatedView(vararg args: Any)


    fun getContext() : Context{
        return rootView.context
    }

    fun startActivity(clazz:Class<*>){
        getContext().startActivity(Intent(getContext(),clazz))
    }

    fun <P:AbsViewPresenter> getPresenter(clazz: Class<P>):P{
        return ViewModelQuick.get(getActivity(),clazz)
    }

    fun getActivity(): AbsActivity {
        return getContext() as AbsActivity
    }

    fun finish(){
        getActivity().finish()
    }
}